<div class="nav-sub w1180">
	<ul class="zoom">
		<li><a  class="on" href="">编辑商品</a></li>
		<li><a href="/crm/product/list">商品列表</a></li>
<!-- 		<li><a href="/crm/product/cate-list">商品分类列表</a></li> -->
		
	</ul>
</div>
<div class="main-ct w1180">
	<a href="javascript:;" class="btn-cs btn-blue btn-fillet mt10">返 回</a>
<form id="commonForm" method="post" action="/crm/product/update">
	<div class="form-info mt20">
		<dl>
			<dt>商户：</dt>
			<dd>
    			<select name="org_id" id="org_id">
    				<?php if ($this->organization):?>
    				<?php foreach ($this->organization as $k=>$v):?>
        				<?php if($this->product['org_id'] == $v['org_id']):?>
                               <option selected value="<?php echo $this->product['org_id'];?>"><?php echo $v['org_name']; ?></option>
                         <?php else:?>
                              <option value="<?php echo $v['org_id']; ?>"><?php echo $v['org_name']; ?></option>
                         <?php endif;?> 
    				
        			<?php endforeach; ?>
        			<?php else:?>
        				<option value="">请选择</option>
    				<?php endif;?>
    			</select>
			</dd>
		</dl>
		
		<dl>
			<dt>商品分类：</dt>
			<dd>
    			<select name="category_id" id="category_id">
    				<option value="">请选择</option>
    				<?php if ($this->good_cate):?>
    				<?php foreach ($this->good_cate as $k=>$v):?>
                         
        				<option value="<?php echo $v['category_id']; ?>"><?php echo $v['category_name']; ?></option>
        			<?php endforeach; ?>
        			<?php else:?>
        				<option value="">请选择</option>
    				<?php endif;?>
    			</select>
			</dd>
		</dl>
		
		<dl>
			<dt>产品名称：</dt>
			<dd><input type="text" class="txt" name="product_name" id="product_name" value="<?php echo $this->product['product_name'];?>"></dd>
		</dl>
		<dl>
			<dt>商品价格：</dt>
			<dd><input type="text" class="txt txt-s mr5" name="product_price" id="product_price" value="<?php echo $this->product['product_price'];?>">（元）</dd>
		</dl>
		<dl>
			<dt>是否推荐：</dt>
			<dd>
				<label class="mr20"><input type="radio" name="recommend" id="recommend" value="1" <?php if($this->product['recommend'] == 1):?> checked="checked" <?php endif;?>> 是</label>
				<label><input type="radio" name="recommend" id="recommend" checked="true" value="0" <?php if($this->product['recommend'] == 0):?> checked="checked" <?php endif;?>> 否</label>
			</dd>
		</dl>
		<dl>
			<dt>是否热销：</dt>
			<dd>
				<label class="mr20"><input type="radio" name="hot" id="hot" value="1" <?php if($this->product['hot'] == 1):?> checked="checked" <?php endif;?>> 是</label>
				<label><input type="radio" name="hot" id="hot" checked="true" value="0" <?php if($this->product['hot'] == 0):?> checked="checked" <?php endif;?>> 否</label>
			</dd>
		</dl>
		<dl>
			<dt>商品图（列表）：</dt>
			<dd class="goods-list">
				<div class="goods-img goods-img-add" id="goods-thumb-image">
					<div class="g-img-ct"  id="cover">
						<img src="<?php if($this->product['product_thumb_image']):?><?php echo $this->product['product_thumb_image'];?><?php else:?>/images/ico/ico-add.png<?php endif;?>" id="add-goods-thumb-image">
						<input type="hidden" name="product_thumb_image" id="product_thumb_image" value="<?php echo $this->product['product_thumb_image'];?>">
					</div>
					<a href="javascript:delImg(this);" class="btn-del" id="del-goods-thumb-image" style="display:none"></a>
				</div>
			</dd>
		</dl>
		<dl>
			<dt>商品图（详情）：</dt>
			<dd class="goods-list">
				<div class="goods-img goods-img-add" id="goods-big-image">
					<div class="g-img-ct" id="cover1">
						<img src="<?php if($this->product['product_big_image']):?><?php echo $this->product['product_big_image'];?><?php else:?>/images/ico/ico-add.png<?php endif;?>" id="add-goods-big-image">
						<input type="hidden" name="product_big_image" id="product_big_image" value="<?php echo $this->product['product_big_image'];?>">
					</div>
					<a href="javascript:delImg(this);" class="btn-del" id="del-goods-big-image" style="display:none"></a>
				</div>
			</dd>
		</dl>		
		<dl>
			<dt>商品描述：</dt>
			<dd><textarea  class="txt" name="product_description" id="product_description"><?php echo $this->product['product_description'];?></textarea></dd>
		</dl>

	</div>
	<p class="mt30 txt-center">
		<input type="hidden" name="product_id" value="<?php echo $this->product['product_id'];?>">
		<input class="input-cs btn-fillet btn-green" type="submit" value="确定" />
	</p>
</form>
</div>
<!-- <link href="/plugins/webUpload/webuploader.css" rel="stylesheet" type="text/css"> -->
<script type="text/javascript" src="/plugins/webUpload/webuploader.js"></script>
<script type="text/javascript">
	var uploader = WebUploader.create({

		// 选完文件后，是否自动上传。
		auto: true,
		duplicate:1,
		swf:'/plugins/webUpload/Uploader.swf',
		// 文件接收服务端。
		server: '/crm/product/upload',
		// 选择文件的按钮。可选。
		// 内部根据当前运行是创建，可能是input元素，也可能是flash.
		pick: {
			id:'#cover',
			multiple:false
		},
		formData :{
			path:"/goods",
		},
		method : 'post',
		// 只允许选择图片文件。
		accept: {
			title: 'Images',
			extensions: 'gif,jpg,jpeg,png',
			mimeTypes: 'image/*'
		}
	});
	uploader.on('uploadSuccess',function(file,response){
		//alert(file.id);
		console.log(file);
		console.log(response);
		if(response.state == 'SUCCESS'){
	 		$('#add-goods-thumb-image').attr("src",response.url);
	 		$('#product_thumb_image').val(response.url);
	 		$('#del-goods-thumb-image').show();
			
		}
	});


	var uploader1 = WebUploader.create({

		// 选完文件后，是否自动上传。
		auto: true,
		duplicate:1,
		swf:'/plugins/webUpload/Uploader.swf',
		// 文件接收服务端。
		server: '/crm/product/upload',
		// 选择文件的按钮。可选。
		// 内部根据当前运行是创建，可能是input元素，也可能是flash.
		pick: {
			id:'#cover1',
			multiple:false
		},
		formData :{
			path:"/goods",
		},
		method : 'post',
		// 只允许选择图片文件。
		accept: {
			title: 'Images',
			extensions: 'gif,jpg,jpeg,png',
			mimeTypes: 'image/*'
		}
	});
	uploader1.on('uploadSuccess',function(file,response){
		//alert(file.id);
		console.log(file);
		console.log(response);
		if(response.state == 'SUCCESS'){
	 		$('#add-goods-big-image').attr("src",response.url);
	 		$('#product_big_image').val(response.url);
	 		$('#del-goods-big-image').show();
			
		}
	});


	//addButton

	    //addButton( pick ) ⇒ Promise

	//添加文件选择按钮，如果一个按钮不够，需要调用此方法来添加。参数跟options.pick一致。

// 	uploader.addButton({
// 	    id: '#cover1',
// 	    //innerHTML: '选择文件11111111'
// 	});

	
	function delImg(obj) {

		console.log(obj);
		$(obj).attr("src","/images/ico/ico-add.png");
    	$(obj).hide();
    	$(obj).val('');
		
		
// 		$('#imgDiv').html('');
// 		$('#imageurl').val('');

// 		var fileid = $(obj).attr('data');
// 		$("#gallery_"+fileid).remove();
// 		$("#imgbox_"+fileid).remove();

// 		$('#banImg_'+id).attr("src","/images/ico/ico-add.png");
//     	$('#banLink_'+id).hide();
//     	$('#banFile_'+id).val('');


// 		$(o).prev('img').attr("src",rst.base64);
// 		$(o).parents('div').next('a').show();
		
	}

	
	$().ready(function() {
		$("#commonForm").validate({
			debug:true,
			rules: {
				
				category_id: {
					required: true
				},
				product_name: {
					required: true
				},
				product_price: {
					required: true
				}
			},
    		submitHandler:function(form){ 
    	            form.submit();
    	    }   
		});

	});

// 	$(document).ready(function(){
// 		//下拉菜单
// 		$('select').select2();
// 	});
</script>